package mysql

import (
	"gorm.io/gorm"
	"time"
)

type User struct {
	gorm.Model
	PhoneNum      string    `gorm:"type:varchar(11);not nil;comment:手机号"`
	Password      string    `gorm:"type:varchar(32);comment:密码"`
	NickName      string    `gorm:"type:varchar(30);comment:昵称"`
	Url           string    `gorm:"type:varchar(255);comment:头像"`
	AccountStatus int       `gorm:"type:int(11);default 0;comment:账号状态"`
	RegisterTime  time.Time `gorm:"type:varchar(30);comment:注册时间"`
	FollowNum     int       `gorm:"type:int(11);default 0;comment:关注数量"`
	FansNum       int       `gorm:"type:int(11);default 0;comment:粉丝数量"`
}

func (u *User) FindUserPhone(db *gorm.DB, num string) error {
	return db.Debug().Where("phone_num=?", num).Find(u).Error
}

func (u *User) RegisterUser(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UPdatePassword(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) UpdateNickName(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
